package com.dong.rabbit_demo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicConfig {
    //定义交换机名称
    private static final String EXCHANGE_NAME="dong_exchange";
    //定义队列名称
    private static final String QUEUE_NAME="dong_queue";


    //声明交换机 direct模式
    @Bean("dongChange")
    public Exchange dongChange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }
    //声明队列
    @Bean("dongQueue")
    public Queue dongQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }



    //队列和交换机绑定
    @Bean
    public Binding bindQueueExchange(@Qualifier("dongQueue") Queue queue, @Qualifier("dongChange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("dong.ha").noargs();
    }


}
